package com.dyh.quickdemo.GoodsRules;


import java.util.List;
import java.util.Map;
import java.util.function.Function;

/*
@Author=Joey Wheeler
@Date=2021/3/6 10:43
*/
public class Rule$2<T,V1,V2> implements Rule<T>{
    private Function<T,V1> mapper1;
    private Function<T,V2> mapper2;
    private List<CheckerAndTip<Checker$2<V1,V2>>> checkerAndTips;

    public Rule$2(Function<T, V1> mapper1, Function<T, V2> mapper2, List<CheckerAndTip<Checker$2<V1, V2>>> checkerAndTips) {
        this.mapper1 = mapper1;
        this.mapper2 = mapper2;
        this.checkerAndTips = checkerAndTips;
    }

    public CheckResult check(T obj){
        V1 v1 = mapper1.apply(obj);
        V2 v2 = mapper2.apply(obj);
        for (CheckerAndTip<Checker$2<V1,V2>> checkerAndTip : checkerAndTips) {
            if (checkerAndTip.getChecker().test(v1,v2))
                continue;
            return new CheckResult(false,checkerAndTip.getTip());
        }
        return new CheckResult(true,"");
    }




}
